package com.my.spring.framework.aop.intercept;

import com.my.spring.framework.aop.aspect.MyAbstractAspectAdvice;
import com.my.spring.framework.aop.aspect.MyJoinPoint;

import java.lang.reflect.Method;

public class MyAfterReturningAdviceInterceptor extends MyAbstractAspectAdvice implements MyMethodInterceptor {
    private MyJoinPoint joinPoint;

    public MyAfterReturningAdviceInterceptor(Method method, Object target) {
        super(method, target);
    }

    private void afterReturning(Object retVal, Method method, Object[] arguments, Object aThis) throws Throwable {
        super.invokeAdviceMethod(joinPoint, retVal, null);
    }

    @Override
    public Object invoke(MyMethodInvocation mi) throws Throwable {
        joinPoint = mi;
        Object retVal = mi.proceed();
        afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());
        return retVal;
    }
}
